import store from '../../store/index.js';
let requestApi = function(opt) {
 	let Basic ='http://qywxhrp.gz5055.com:2122'
 	let token = {
 		'content-Type': 'application/json',
 	}
	store.commit("add")
	if(opt.code){
		token = {
			'content-Type': 'application/json',
			'account':'develop',
			'usercode':JSON.parse(uni.getStorageSync('user')).user_code
		}
	}
	uni.stopPullDownRefresh()
 	uni.showLoading({
 		title: '加载中',
		mask:true
 	})
 	uni.request({
 		// url:Basic+opt.url,
		url:opt.url,
 		data: opt.data ? opt.data : '',
 		method: opt.method,
 		header: token, 
 		timeout: 50000,
 		success: (res) => {
			store.commit("reduce")
			if (res.data.STATUS=='SUCCESS') {
				opt.event.success(res)
			}
			else{
				console.log(opt.data)
				alert(JSON.stringify(res))
			}
 		},
 		fail: (err) => {
			store.commit("reduce")
			uni.showToast({
				icon:'none',
				title:'返回值错误'
			})
			opt.event.fail(err)
 		},
 		complete: (all) => {
			if(store.state.loading==0){
				uni.hideLoading()
			}
			if(all.statusCode=='404'){
				uni.showToast({
					icon:'none',
					title:'网络似乎有点问题'+all.statusCode
				})
			}
 		}
 	})
 }
 export default {
 	requestApi
 }
